<?php
namespace App\Http\Controllers\Api\Ly;
use App\Common\Responses;
use App\Models\Fang;
use App\Models\lak\Residential;
use App\Utils\Logic\Ly\FangSearchLogic;
use App\Utils\Service\Ly\EsServer;
use App\Utils\Adapter\Map;
use App\Utils\Thirdparty\Map\Amap;
use App\Utils\Thirdparty\Map\BaiduMap;
use App\Utils\Thirdparty\Map\Wechat;
use Elasticsearch\ClientBuilder;
use Illuminate\Http\Request;
use App\Utils\Lib\MyEs;
class CommuteController
{

    //创建索引
    public function createFangEsIndex()
    {
        EsServer::EsIndex()->createIndex();
        try{
            $data=Fang::all();
            //数据添加到es
            foreach ($data as $val)
            {
                $val['address']= json_decode($val['address'],true);
                EsServer::EsIndex()->addEs('ly_fang',$val->toArray());
            }
            return Responses::success([],'200','添加成功');
        }catch (\Exception $e){
            return Responses::error([],0,$e->getMessage());
        }
    }

    //es搜索
    public function searchHouse(Request $request)
    {
        try {
            $region=$request->get('region');
            $address=$request->get('address');
            $data=FangSearchLogic::searchHouse($address,$region);
            return Responses::success($data,'200','success');
        }catch (\Exception $e)
        {
            return Responses::error([],0,$e->getMessage());
        }
    }
}
